package com.peanut.controller;


import com.mvc.annotation.RequestMapping;
import com.mvc.annotation.RequestParam;
import com.mvc.annotation.ResponseBody;
import com.peanut.entity.BookChapter;
import com.peanut.entity.Game;
import com.peanut.entity.JsonResult;
import com.peanut.entity.Page;
import com.peanut.service.BookChapterService;
import com.peanut.service.GameService;
import com.spring.annotation.Autowired;
import com.spring.annotation.Controller;


/**
 * 开放给所有用户，不需要登录，不需要权限
 *
 * 限制只能查操作！！！！
 */


@Controller
public class PublicUserAccessController {
	@Autowired
	private GameService gameService;
	
	
	@Autowired
	private BookChapterService bookChapterService;
	
	
	/**
	 * 获取游戏列表 ，根据类型
	 */
	@ResponseBody
	@RequestMapping("/public/gameList.do")
	public JsonResult gameList(@RequestParam(required = true, defaultValue = "1") Integer currentPage,
							   @RequestParam(required = true, defaultValue = "10") Integer pageSize,
							   @RequestParam(required = true, defaultValue = "0") Integer platform) {
		if (currentPage < 1) {
			currentPage = 1;
		}
		if (pageSize < 1) {
			pageSize = 10;
		}
		if (platform < 0 || platform > 2) {
			platform = 0;
		}
		
		Page<Game> gamePage = gameService.queryNormalGameByPlatform(currentPage, pageSize, platform);
		return JsonResult.success(gamePage);
	}
	
	
	/**
	 * 获取小说章节内容  根据ID
	 */
	@ResponseBody
	@RequestMapping("/public/queryBookChapterContentById.do")
	public JsonResult queryBookChapterContentById(@RequestParam(required = true, defaultValue = "10043") Integer bookChapterId) {
		BookChapter bookChapter = bookChapterService.getById(bookChapterId);
		return JsonResult.success(bookChapter);
	}
	
	
	
}
